package {{ packageSources }}.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Sets;
import io.github.toquery.framework.webmvc.domain.ResponseParam;
import io.github.toquery.framework.curd.controller.AppBaseCurdController;

import {{ packageSources }}.entity.{{ properCase name }};
import {{ packageSources }}.service.I{{ properCase name }}Service;

import java.util.Set;

/**
* @author toquery
* @version 1
*/
@RestController
@RequestMapping("{{ dashCase name }}")
public class {{ properCase name }}Controller extends AppBaseCurdController<I{{ properCase name }}Service, {{ properCase name }}, Long> {

    @GetMapping
    public ResponseParam query() {
        return super.query();
    }

    @GetMapping("/list")
    public ResponseParam list() {
        return super.list();
    }

    @PostMapping
    public ResponseParam save(@Validated @RequestBody {{ properCase name }} {{ camelCase name }}) {
        return super.save({{ camelCase name }});
    }

    @PutMapping
    public ResponseParam update(@RequestBody {{ properCase name }} {{ camelCase name }}) {
        return super.update({{ camelCase name }}, Sets.newHashSet({{#each fieldList}}"{{ camelCase fieldName }}",{{/each}}));
    }

    @DeleteMapping
    public void delete(@RequestParam Set<Long> ids) {
        super.delete(ids);
    }

    @GetMapping("{id}")
    public ResponseParam detail(@PathVariable Long id) {
        return super.detail(id);
    }
}
